
# -*- coding: UTF-8 -*-

from iHome.libs.yuntongxun.CCPRestSDK import REST
import ConfigParser
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
# 主账号
accountSid = '8a216da86010e69001602bf5106f0bb7';

# 主账号Token
accountToken = '70370af687804bdd8c90f74495e63511';

# 应用Id
appId = '8a216da86010e69001602bf510cd0bbe';

# 请求地址，格式如下，不需要写http://
serverIP = 'app.cloopen.com'

# 请求端口
serverPort = '8883'

# REST版本号
softVersion = '2013-12-26'

class CCP(object):
    def __new__(cls, *args, **kwargs):
        if not hasattr(cls,"_instance"):
            cls._instance = super(CCP,cls).__new__(cls,*args,**kwargs)
            cls._instance.rest = REST(serverIP,serverPort,softVersion)
            cls._instance.rest.setAccount(accountSid,accountToken)
            cls._instance.rest.setAppId(appId)
        return cls._instance
    def send_template_sms(self,to,datas,temp_id):
        '''
        发送短信
        :param to:
        :param datas:
        :param temp_id:
        :return: 返回1代表发送成功，返回0代表发送失败
        '''
        result = self.rest.sendTemplateSMS(to,datas=datas,tempId=temp_id)
        if result.get('statusCode') == "000000":
            # 返回1代表发送成功
            return 1
        else:
            # 返回0代表发送失败
            return 0
if __name__ == '__main__':
    CCP().send_template_sms("15853721925",['88888888',100],"1")
# sendTemplateSMS("15853721925",["888888", 100], "1")

